package com.example.prototipoasincrono.async;

import java.io.IOException;

import com.esotericsoftware.kryonet.Connection;
import com.esotericsoftware.kryonet.Listener;
import com.esotericsoftware.kryonet.Server;
import com.esotericsoftware.minlog.Log;

public class Servidor {
	Server server;
	
	public Servidor() throws IOException{
		server = new Server() {
			protected Connection newConnection () {
				// By providing our own connection implementation, we can store per
				// connection state without a connection ID to state look up.
				return new UserConnection();
			}
		};
		Network.register(server);
		server.addListener(new Listener(){

			@Override
			public void disconnected(Connection connection) {
				super.disconnected(connection);
			}

			@Override
			public void received(Connection connection, Object object) {
				
			}

			@Override
			public void idle(Connection connection) {
				// TODO Auto-generated method stub
				super.idle(connection);
			}
			
		});
		server.bind(Network.port);
		server.start();
		
		System.out.println("Server conectado en puerto " + Network.port);
	}
	
	
// This holds per connection state.
	static class UserConnection extends Connection {
		public String name;
		public String password;
	}
	
	public static void main (String[] args) throws IOException {
		Log.set(Log.LEVEL_ERROR);
		new Servidor();
	}
}
